package com.zmj.framework.dao.jdbc;

import java.util.List;

import javax.annotation.PostConstruct;
import javax.sql.DataSource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

@Repository("jdbcTemplate")
public class FrmJdbcTemplate extends JdbcTemplate {
	@Autowired
	private DataSource dataSource;

	@PostConstruct
	public void injectSessionFactory() {
		super.setDataSource(dataSource);
	}

	public Object queryForBean(String sql, Class elementType) throws DataAccessException {
		try {
			return queryForObject(sql, new FrmRowMapper(elementType));
		} catch (Exception ex) {
		}
		return null;
	}

	public List queryForList(String sql, Class elementType) throws DataAccessException {
		return query(sql, new FrmRowMapper(elementType));
	}
}